package com.wson.widget.render.compass.framework;

import java.util.Collection;

import com.wson.behavior.ctrl.IBehavior;
import com.wson.constant.compass.IRuntimeConstant;
import com.wson.model.basic.IBasicView;
import com.wson.model.clouddisk.file.ICodiskFileManip;
import com.wson.model.clouddisk.file.ICodiskFileMeta;
import com.wson.model.clouddisk.file.ICodiskFileView;
import com.wson.root.util.LinguisticUtil;
import com.wson.root.util.LoggerUtil;
import com.wson.widget.render.IRenderParam;
import com.wson.widget.render.layout.impl.ModelExtendTableRender;

public class DocumentsRender extends ModelExtendTableRender {
	
	public final  static String  PARAM_PARENTFOLDER = "PARENTFOLDER";
	public final  static String  PARAM_CODISKACCOUNTID = "CODISKACCOUNTID";	
	
	@IRenderParam(name=PARAM_PARENTFOLDER)
	private String parentFolder;
	
	@IRenderParam(name=PARAM_CODISKACCOUNTID)
	private Long codiskAccountID;

	@Override
	public String code() {
		return "DOCUMENTSRENDER";
	}
	
	

	public String getParentFolder() {
		return parentFolder;
	}



	public void setParentFolder(String parentFolder) {
		this.parentFolder = parentFolder;
	}



/*	@Override
	public IBasicView getModel() {
		ICodiskFileView model = (ICodiskFileView) super.getModel();
		((ICodiskFileManip)model).setParentFolder(this.getParentFolder());
		return model;
	}
*/


	public Long getCodiskAccountID() {
		return codiskAccountID;
	}



	public void setCodiskAccountID(Long codiskAccountID) {
		this.codiskAccountID = codiskAccountID;
	}



	@Override
	public Long getModelMetaID() {
		return ICodiskFileMeta.META_ID;
	}



	@Override
	public String getEmptyText() {
		return this.getMessage(IRuntimeConstant.SYNC_NOFILES);
	}

	

	@Override
	public IBehavior render() {
		//System.out.println("this.getParentFolder() "+this.getParentFolder());
		if(this.getModels()==null){
			ICodiskFileView model = (ICodiskFileView) super.getModel();
			((ICodiskFileManip)model).setParentFolder(this.getParentFolder());
			((ICodiskFileManip)model).setAccountID(this.getCodiskAccountID());
			try{
				Collection<IBasicView> objs = model.selfQuery();
				for(IBasicView obj:objs){
					if(obj.getName()!=null){
						
						if(obj.getName().endsWith(".docx") 
								|| obj.getName().endsWith(".doc"))
							((ICodiskFileManip)obj).setIconLink("/wscompassweb/images/codisk/docx.gif");
						else if(obj.getName().endsWith(".pptx") 
								|| obj.getName().endsWith(".ppt"))
							((ICodiskFileManip)obj).setIconLink("/wscompassweb/images/codisk/pptx.gif");
						else if(obj.getName().endsWith(".xlsx") 
								|| obj.getName().endsWith(".xls"))
							((ICodiskFileManip)obj).setIconLink("/wscompassweb/images/codisk/xlsx.gif");
						else if(obj.getName().endsWith(".pdf"))
							((ICodiskFileManip)obj).setIconLink("/wscompassweb/images/codisk/pdf.gif");
						
						if(obj.getShortText()==null)
							((ICodiskFileManip)obj).setShortText(LinguisticUtil.generateExpression(obj.getName()
									));
					}
				}
				this.setModels(objs);
			}
			catch(Exception ex){
				LoggerUtil.DEBUG(ex);
			}
		}
	
		return super.render();
	}
	
	
	

}
